
package com.railway.filter;

import java.io.IOException;

import javax.servlet.Filter; import javax.servlet.FilterChain; import
javax.servlet.ServletException; import javax.servlet.ServletRequest; import
javax.servlet.ServletResponse; import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest; import
javax.servlet.http.HttpServletResponse;
 
/**
* 用于过滤访问添加、编辑、搜索页面
*
*/
@WebFilter("/*") 
public class EditAddSearchFilter implements Filter{
	@Override 
	public void doFilter(ServletRequest request, ServletResponse
		  response, FilterChain chain) throws IOException, ServletException {
		  HttpServletRequest req = (HttpServletRequest)request;
		  
		  HttpServletResponse resp = (HttpServletResponse) response;
		  
		  String uri = req.getRequestURI(); 
		  if((uri.contains("localhost:8080/"+"addAdmin.jsp")|| uri.contains("localhost:8080/"+"editAdmin.jsp") || uri.contains("localhost:8080/"+"addUser.jsp") ||uri.contains("localhost:8080/"+"editUser.jsp") || uri.contains("localhost:8080/"+"insertLcu.jsp"))) { 
			  resp.sendRedirect("/12306/menu.jsp");
		  }else { 
			  chain.doFilter(request, response); 
		  }
		  
	}
		 
}
